using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TwoSixPanel : MonoBehaviour
{
    List<six> sixs = new List<six>()
    {
        new six("小明", 100, 1),
        new six("小红", 20, 2),
        new six("小刚", 10, 3),
        new six("小李", 5, 4),
        new six("小王", 1, 5),
        new six("小张", 0, 6),
        new six("小赵", 0, 7),
        new six("小钱", 0, 8),
        new six("小孙", 0, 9),
    };
    public List<TwoSixItem> twoSixItems = new List<TwoSixItem>();
    public TwoSixItem TwoSixItem;
    public Transform group;
    six you;
    private void OnEnable()
    {
        if (you != null)
        {
            you.num = TwoPanel.Ins.MoneyNum; // Update the "you" item with the current money number
        }
        sixs.Sort((a, b) => b.num.CompareTo(a.num)); // Sort by num in descending order
        for (int i = 0; i < sixs.Count; i++)
        {
            sixs[i].ranking = i + 1; // Update ranking based on sorted order
            CreateItem(sixs[i], i);
            twoSixItems[i].gameObject.SetActive(true);
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        you = new six("你", TwoPanel.Ins.MoneyNum, 1); // Example of a single item, not used in the current context
        sixs.Add(you); // Add the "you" item to the list
        for (int i = 0; i < sixs.Count; i++)
        {
            CreateItem(sixs[i], i);
            twoSixItems[i].gameObject.SetActive(true);
        }
        TwoSixItem.gameObject.SetActive(false); // Hide the template item
    }

    private void CreateItem(six six, int i)
    {
        if (twoSixItems.Count <= i)
        {
            twoSixItems.Add(Instantiate(TwoSixItem, group));
        }
        twoSixItems[i].init(six);
    }

    // Update is called once per frame
    void Update()
    {

    }
}
public class six
{
    public six(string name, int num, int ranking)
    {
        this.name = name;
        this.num = num;
        this.ranking = ranking;
    }
    public string name;
    public int num;
    public int ranking;
}
